package cn.edu.stu.syllabus.repository.token.remote;

import javax.inject.Inject;

import cn.edu.stu.syllabus.api.TokenApi;
import cn.edu.stu.syllabus.di.qualifier.Remote;
import cn.edu.stu.syllabus.di.scope.FragmentScoped;
import cn.edu.stu.syllabus.repository.token.TokenConverter;
import cn.edu.stu.syllabus.repository.token.TokenDataSource;
import cn.edu.stu.syllabus.repository.token.local.TokenEntry;
import rx.Observable;
import rx.functions.Func1;

/**
 * Created by daidaijie on 2017/4/25.
 */

public class TokenRemoteDataSource implements TokenDataSource {

    private TokenApi mTokenApi;

    public TokenRemoteDataSource(TokenApi tokenApi) {
        mTokenApi = tokenApi;
    }

    @Override
    public Observable<TokenEntry> getToken(String code) {
        return mTokenApi
                .getToken(code)
                .map(new Func1<Token, TokenEntry>() {
                    @Override
                    public TokenEntry call(Token token) {
                        return TokenConverter.convert(token);
                    }
                });
    }
}
